package com.yxhl.zoume.core.tripsmgmt.ui.fragment.tripsdetail;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.yxhl.protobuf.BizOrder;
import com.yxhl.protobuf.Contract;
import com.yxhl.protobuf.JudgeEntry;
import com.yxhl.protobuf.OrderBizType;
import com.yxhl.protobuf.OrderPayStatus;
import com.yxhl.protobuf.OrderRideStatus;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.custom.ListViewWrap;
import com.yxhl.zoume.common.ui.fragment.BaseFragment;
import com.yxhl.zoume.core.func.appraisal.model.AppraisalDriverInfo;
import com.yxhl.zoume.core.tripsmgmt.info.PayStatus;
import com.yxhl.zoume.core.tripsmgmt.info.RideStatus;
import com.yxhl.zoume.core.tripsmgmt.presenter.detail.DetailTripPresenter;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.TripDetailContainerActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.adapter.PassengerDetailAdapter;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderEvent;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderFromDialogEvent;
import com.yxhl.zoume.core.tripsmgmt.ui.fragment.dialog.CancelTicketDialogFragment;
import com.yxhl.zoume.core.tripsmgmt.ui.fragment.dialog.GetTicketCodeDialogFragment;
import com.yxhl.zoume.core.tripsmgmt.view.unit.CancelOrderView;
import com.yxhl.zoume.core.tripsmgmt.view.unit.CommentOnDriverView;
import com.yxhl.zoume.core.tripsmgmt.view.unit.RefundTicketView;
import com.yxhl.zoume.data.rxbus.RxBus;
import com.yxhl.zoume.di.component.trip.DaggerTripComponent;
import com.yxhl.zoume.di.module.ActivityModule;
import com.yxhl.zoume.di.module.trip.TripModule;
import com.yxhl.zoume.domain.interactor.ZMEventSubscriber;
import com.yxhl.zoume.utils.CollectionUtils;
import com.yxhl.zoume.utils.LOG;
import com.yxhl.zoume.utils.PromptUtils;
import com.yxhl.zoume.utils.ZMDialog;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;
import rx.functions.Action1;
import rx.subscriptions.CompositeSubscription;

/**
 * 行程详情页,旧版本的行程详情都复用此类
 */
public class DetailTripFragment extends BaseFragment implements CommentOnDriverView, RefundTicketView, CancelOrderView {

    private static final String TAG = "HistoryTripsDetailFrag";

    private static final int ROTATION_DEGREE = 180;

    @BindView(R.id.ll_history_trips_detail_root)
    LinearLayout mLinearLayout;
    @BindView(R.id.rl_fragment_trip_detail_header)
    RelativeLayout mHeaderRl;

    @BindView(R.id.iv_include_trips_item_icon)
    ImageView bizTypeIcon;

    @BindView(R.id.tv_include_trips_item_start_station)
    TextView startStation;
    @BindView(R.id.tv_include_trips_item_start_time)
    TextView startTime;
    @BindView(R.id.tv_include_trips_item_start_data)
    TextView startData;
    @BindView(R.id.tv_include_trips_item_destination)
    TextView destination;

    @BindView(R.id.tv_history_trips_item_price)
    TextView price;
    @BindView(R.id.tv_history_trips_item_amount)
    TextView amount;
    @BindView(R.id.tv_history_trip_item_order_status)
    TextView orderStatus;

    //-----current trip bottom view

    @BindView(R.id.rl_trips_item_bottom_container)
    RelativeLayout mCurrentTripBottom;
    @BindView(R.id.tv_trips_item_trip_status)
    TextView tripStatusTv;

    @BindView(R.id.tv_trips_item_fee)
    TextView feeTv;
    @BindView(R.id.tv_trips_item_passenger_amount)
    TextView passengerAmountTv;

    @BindView(R.id.rl_trips_item_order_status)
    RelativeLayout orderStatusRl;
    @BindView(R.id.tv_trips_item_order_status)
    TextView orderStatusTv;
    @BindView(R.id.iv_current_trips_item_order_status)
    ImageView orderStatusIv;
    //------end


    //-----history trip bottom view
    @BindView(R.id.ll_history_trips_bottom)
    RelativeLayout mTripMgmtBottom;

    @BindView(R.id.ll_trip_detail_account)
    RelativeLayout llCountContent;


    @BindView(R.id.tv_trip_detail_amount)
    TextView tvAmount;//乘车人数
    @BindView(R.id.iv_trip_detail_show_passenger_layout)
    RelativeLayout RelativePassengerIndicator;
    @BindView(R.id.iv_trip_detail_show_passenger_indicator)
    ImageView ivPassengerIndicator;
    //-----------end

    @BindView(R.id.lv_trip_detail_fragment_route)
    ListViewWrap innerListView;

    @BindView(R.id.tv_trip_detail_pay_Id)
    TextView tvOrderId;//订单编号
    @BindView(R.id.tv_trip_detail_pay_data)
    TextView tvGmtCreate;//下单时间
    @BindView(R.id.tv_trip_detail_pay_money)
    TextView tvTotalFee;//支付金额

    @BindView(R.id.ll_trip_detail_charter_content)
    LinearLayout llCharterContent;//接驳车整个父控件
    @BindView(R.id.tv_trip_detail_charter_start_station)
    TextView tvCharterStartStation;//接驳车始发位置
    @BindView(R.id.tv_trip_detail_charter_end_station)
    TextView tvCharterEndStation;//接驳车终点站
    @BindView(R.id.tv_trip_detail_driver_name)
    TextView tvDriverName;//司机姓名
    @BindView(R.id.tv_trip_detail_charter_vehicle)
    TextView tvCharterVehicleNo;//接驳车车牌号
    @BindView(R.id.iv_trip_detail_charter_phone)
    ImageView ivCharterCellPhone;//接驳车电话按钮

    @BindView(R.id.ll_trip_detail_bus_content)
    LinearLayout busContentLl;
    @BindView(R.id.tv_trip_detail_bus_vehicle_no)
    TextView busVehicleNoTv;//大巴车牌号

    @BindView(R.id.ll_history_trips_detail_special_driver)
    LinearLayout mSpecialDriverLl; //接驾司机根局部
    @BindView(R.id.tv_history_trip_detail_special_driver_name)
    TextView mSpecialDriverInfoTv;

    @BindView(R.id.ll_history_trips_cancel_order)
    RelativeLayout mCancelOrderReveal;

    //arguments
    @Inject
    DetailTripPresenter mDetailTripPresenter;

    private PassengerDetailAdapter mPassengerDetailAdapter;
    /**
     * 跳转 携带来的数据
     */
    private BizOrder mBizOrder;
    private float mFromDegrees = 0;
    private float mToDegrees = 180;

    /**
     * 乘客列表信息是否展开
     */
    private boolean needOpen = true;
    /**
     * 乘客集
     */
    private List<Contract> mPassengerList;

    /**
     * 取消订单等待对话框
     */
    private MaterialDialog mDialogForWaitingCancel;

    private CompositeSubscription mCompositeSubscription;


    public DetailTripFragment() {
        // Required empty public constructor
    }

    public static DetailTripFragment newInstance(BizOrder bizOrder) {
        DetailTripFragment fragment = new DetailTripFragment();
        if (bizOrder != null) {
            Bundle bundle = new Bundle();
            bundle.putSerializable(UIConstants.TripContainer.KEY_ORDER_HISTORY_DETAIL, bizOrder);
            fragment.setArguments(bundle);
        }
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleArguments();
        onRxBusEvent();
    }

    private void handleArguments() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mBizOrder = (BizOrder) arguments.getSerializable(UIConstants.TripContainer.KEY_ORDER_HISTORY_DETAIL);
        }
    }

    private void onRxBusEvent() {
        mCompositeSubscription = new CompositeSubscription();
        mCompositeSubscription.add(toSubscription(CancelTripOrderFromDialogEvent.class,
                new Action1<CancelTripOrderFromDialogEvent>() {
                    @Override
                    public void call(CancelTripOrderFromDialogEvent cancelTripOrderFromDialogEvent) {
                        if (mDetailTripPresenter != null) {
                            mDetailTripPresenter.cancelOrder(mBizOrder.getOrderSerial());
                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        ));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        ViewCompat.setTransitionName(mHeaderRl, UIConstants.TripContainer.TRIP_DETAIL_SHARE_ELEMENT);
        mDetailTripPresenter.attachView(this);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initialViewVisibility(mBizOrder);
        bindData(mBizOrder);
    }

    @OnClick(R.id.ll_history_trips_cancel_order)
    void onOrderCancelClick(View view) {
        ZMDialog dialog = new ZMDialog.Builder(getActivity())
                .setMessage(getString(R.string.dialog_cancel_trip_order_content))
                .setPositiveMessage(getString(R.string.dialog_confirm))
                .setNegativeMessage(getString(R.string.dialog_cancel))
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        RxBus.getInstance().send(new CancelTripOrderFromDialogEvent());
                    }
                })
                .setNegativeClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        //super.onNext(o);

                    }
                })
                .show();


    }

    @OnClick(R.id.iv_trip_detail_show_passenger_layout)
    void onPassengerIndicatorClick(View view) {
        RotateAnimation rotateAnimation = new RotateAnimation(
                mFromDegrees, mToDegrees,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(500);
        rotateAnimation.setFillAfter(true);
        rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                //转动度数调整
                mFromDegrees = mToDegrees;
                mToDegrees += ROTATION_DEGREE;

                if (needOpen) {
                    innerListView.setVisibility(View.VISIBLE);
                } else {
                    innerListView.setVisibility(View.GONE);
                }
                needOpen = !needOpen;
            }

            @Override
            public void onAnimationEnd(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });

        ivPassengerIndicator.startAnimation(rotateAnimation);
    }

    /**
     * 初始化 可见性设置(此外,数据绑定也会影响控件可见性)
     *
     * @param bizOrder
     */
    private void initialViewVisibility(BizOrder bizOrder) {

        currentTripBottomViewVisibility(bizOrder);

        busVehicleLayoutVisibility(bizOrder);
//        charterContentVisibility(bizOrder);

        passengerIndicatorVisibility(bizOrder);
        totalFeeVisibility(bizOrder);
        specialDriverLayoutVisibility(bizOrder);

        cancelOrderLayoutVisibility(bizOrder);
    }


    /**
     * 初始化卡片底栏
     *
     * @param bizOrder
     */
    private void currentTripBottomViewVisibility(BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderPayStatus payStatus = bizOrder.getPayStatus();
            switch (payStatus) {
                case CREATED:
                case PAID:
                    mCurrentTripBottom.setVisibility(View.VISIBLE);
                    mTripMgmtBottom.setVisibility(View.GONE);
                    break;
                default:
                    mCurrentTripBottom.setVisibility(View.GONE);
                    mTripMgmtBottom.setVisibility(View.VISIBLE);

            }
        }
    }

    /**
     * 初始化"取消订单"可见性
     *
     * @param bizOrder
     */
    private void cancelOrderLayoutVisibility(BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderPayStatus payStatus = bizOrder.getPayStatus();
            switch (payStatus) {
                case CREATED:
                    mCancelOrderReveal.setVisibility(View.VISIBLE);
                    break;
                default:
                    mCancelOrderReveal.setVisibility(View.GONE);
            }
        }
    }

    /**
     * 初始化巴士车牌可见性
     *
     * @param bizOrder
     */
    private void busVehicleLayoutVisibility(BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderBizType bizType = bizOrder.getBizType();

            long driverId = bizOrder.getDriverId();
            if (driverId != 0) {
                busContentLl.setVisibility(View.GONE);
            } else {
                switch (bizType) {
                    case OBT_DIY_BUS:
                    case TICKET:
                        busContentLl.setVisibility(View.VISIBLE);
                        break;
                    default:
                        busContentLl.setVisibility(View.GONE);
                }
            }
        }
    }

    /**
     * 初始化快车司机一览可见性
     *
     * @param bizOrder
     */
    private void specialDriverLayoutVisibility(BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderBizType bizType = bizOrder.getBizType();

            switch (bizType) {
                case ORDER_BIZ_SHARE:
                case ORDER_BIZ_CHARTER:
                    if (TextUtils.isEmpty(bizOrder.getDriverName()) || TextUtils.isEmpty(bizOrder.getVehicleNo())) {
                        mSpecialDriverLl.setVisibility(View.GONE);
                    } else {
                        mSpecialDriverLl.setVisibility(View.VISIBLE);
                    }
                    break;
                default:
                    mSpecialDriverLl.setVisibility(View.GONE);
            }
        }
    }

    /**
     * 初始化支付金额一栏可见性
     *
     * @param bizOrder
     */
    private void totalFeeVisibility(BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderBizType bizType = bizOrder.getBizType();

            switch (bizType) {
                case ORDER_BIZ_SHARE:
                case ORDER_BIZ_CHARTER:
                    tvTotalFee.setVisibility(View.GONE);
                    break;
                default:
                    tvTotalFee.setVisibility(View.VISIBLE);
            }
        }
    }

    /**
     * 初始化乘客列表箭头图标可见性
     *
     * @param bizOrder
     */
    private void passengerIndicatorVisibility(BizOrder bizOrder) {
        if (bizOrder != null) {
            mPassengerList = bizOrder.getPassengerList();
            if (mPassengerList != null && mPassengerList.size() > 0) {
                ivPassengerIndicator.setVisibility(View.VISIBLE);
            } else {
                ivPassengerIndicator.setVisibility(View.INVISIBLE);
            }
        }
    }

//    /**
//     * 初始化接驳车一栏可见性
//     *
//     * @param bizOrder
//     */
//    private void charterContentVisibility(BizOrder bizOrder) {
//        if (bizOrder != null) {
//            List<BizOrder> subOrders = bizOrder.getSubOrdersList();
//            llCharterContent.setVisibility(View.GONE);
//            if (subOrders == null) {//没有有接驳车
//                return;
//            }
//            if(subOrders.size() == 0){
//                return;
//            }
//            BizOrder subBizOrder = subOrders.get(0);
//            if(subBizOrder == null ){
//                return;
//            }
//            if(subBizOrder.getOrderId() == 0){
//                return;
//            }
//
//            //有接驳车
//            llCharterContent.setVisibility(View.VISIBLE);
//
//                if (subOrders != null) {
//                    TripOrder charterOrder = subOrders.get(0);
//                    final String driverMobile = charterOrder.getDriverMobile();
//                    //当有接驳车师傅手机号时,拨打电话图标显示
//                    if (TextUtils.isEmpty(driverMobile)) {
//                        ivCharterCellPhone.setVisibility(View.GONE);
//                    } else {
//                        ivCharterCellPhone.setVisibility(View.VISIBLE);
//
//                        ivCharterCellPhone.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                DeviceUtils.dialTelPhone(getActivity(), driverMobile);
//                            }
//                        });
//                    }
//
//                    //接驳车相关赋值
//                    if (charterOrder != null) {
//
//                        if (TextUtils.isEmpty(charterOrder.getStart())) {
//                            tvCharterStartStation.setText(charterOrder.getStartCity());
//                        } else {
//                            tvCharterStartStation.setText(charterOrder.getStart());
//                        }
//
//                        if (TextUtils.isEmpty(charterOrder.getDestination())) {
//                            tvCharterEndStation.setText(charterOrder.getEndCity());
//                        } else {
//                            tvCharterEndStation.setText(charterOrder.getDestination());
//                        }
//
//                        tvCharterVehicleNo.setText(charterOrder.getVehicleNo());
//                        if (bizOrder.getDriverName() != null && bizOrder.getDriverName().length() > 0) {
//                            tvDriverName.setText(String.format(getString(R.string.route_detail_drivername), bizOrder.getDriverName().charAt(0)));
//                        }
//                    }
//                }
//
//        }
//    }

    /**
     * 绑定数据到UI
     *
     * @param bizOrder
     */
    private void bindData(BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderBizType bizType = bizOrder.getBizType();
            setBizTypeIcon(bizType);
            setStartStation(bizOrder.getStart());
            setDestination(bizOrder.getDestination());
            String gmtDepart = bizOrder.getGmtDepart();
            setStartTimeAndData(gmtDepart);

            setBottomView(bizOrder);
            setCurrentTripBottomView(bizOrder);

            setPassengerList(bizOrder);
            setPassengerAmount(bizOrder.getAmount());
            setBusVehicleLayout(bizOrder.getVehicleNo());

            setOrderId(bizOrder.getOrderSerial());
            setGmtCreate(bizOrder.getGmtCreate());
            setTotalFee(bizOrder.getTotalFee());

            setSpecialDriverInfo(bizOrder.getDriverName(), bizOrder.getVehicleNo());
        }

    }

    private void setCurrentTripBottomView(BizOrder bizOrder) {
        if (bizOrder != null) {
            setTripStatus(bizOrder);
            setCurrentTripPrice(bizOrder);
            setCurrentTripOrderStatus(bizOrder);
        }
    }

    //-----------------------------

    /**
     * 设置行程状态
     *
     * @param bizOrder
     */
    private void setTripStatus(BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderBizType bizType = bizOrder.getBizType();
            OrderRideStatus rideStatus = bizOrder.getRideStatus();
            OrderPayStatus payStatus = bizOrder.getPayStatus();

            if (!CollectionUtils.isEmpty(bizOrder.getSubOrdersList())) {
                BizOrder subOrder = bizOrder.getSubOrdersList().get(0);
                subOrderRideStatusFilter(subOrder, tripStatusTv);
            } else {
                bizTypeAndRideStatusFilter(payStatus, bizType, rideStatus, tripStatusTv);
            }
        }
    }

    /**
     * 接驳车行程状态过滤器
     *
     * @param subOrder
     */
    private void subOrderRideStatusFilter(BizOrder subOrder, TextView filterTv) {
        OrderRideStatus rideStatus = subOrder.getRideStatus();
        String rideStatusStr;
        if (subOrder != null) {
            switch (rideStatus) {
                case UN_SEND://接驳车未派车
                    rideStatusStr = getString(R.string.route_detail_no_shuttle_bus);
                    break;
                case UN_TAKEN://接驳车已派车
                    rideStatusStr = getString(R.string.route_detail_wait_shuttle_bus);
                    break;
                case TAKEN://接驳车已上车
                    rideStatusStr = getString(R.string.route_detail_taken_shuttle_bus);
                    break;
                case ARRIVED://接驳车已到站，等候巴士
                    rideStatusStr = getString(R.string.route_detail_taken_arrive_bus);
                    break;
                case DROP://接驳车未乘坐
                    rideStatusStr = getString(R.string.route_detail_taken_cancel_bus);
                    break;
                default:
                    rideStatusStr = "";
            }
            filterTv.setText(rideStatusStr);

        }
    }

    /**
     * 乘车状态和车类型过滤器
     *
     * @param
     * @param rideStatus
     */
    private void bizTypeAndRideStatusFilter(OrderPayStatus payStatus, OrderBizType bizType, OrderRideStatus rideStatus, TextView filterTv) {
        String rideStatusStr;
        switch (bizType) {
            case ORDER_BIZ_CHARTER:
            case ORDER_BIZ_SHARE:
                rideStatusStr = getRideStatusForCar(rideStatus);
                break;
            case TICKET:
                switch (payStatus) {
                    case CREATED:
                        rideStatusStr = getString(R.string.trip_management_ride_status_wait_pay);
                        break;
                    default:
                        rideStatusStr = getString(R.string.trip_management_ride_status_paid);
                        break;
                }
                break;
            default:
                rideStatusStr = "";
        }
        filterTv.setText(rideStatusStr);
    }

    /**
     * 定制巴士的行程状态
     *
     * @param status
     * @return
     */
    @NonNull
    private String getRideStatusForBus(int status) {
        RideStatus rideStatus = RideStatus.getRideStatusByValue(status);
        String rideStatusStr;
        switch (rideStatus) {
            case UN_SEND://巴士未派车
                rideStatusStr = getString(R.string.route_detail_no_bus);
                break;
            case UN_TAKEN://巴士未上车
                rideStatusStr = getString(R.string.route_detail_wait_bus);
                break;
            case TAKEN://巴士已上车
                rideStatusStr = getString(R.string.route_detail_take_bus);
                break;
            case ARRIVED://巴士已到站
                rideStatusStr = getString(R.string.route_detail_arrive_bus);
                break;
            case CANCEL://巴士未乘坐
                rideStatusStr = getString(R.string.route_detail_cancel_bus);
                break;
            default:
                rideStatusStr = "";
        }
        return rideStatusStr;
    }

    /**
     * 快车的行程状态
     *
     * @param rideStatus
     * @return
     */
    @NonNull
    private String getRideStatusForCar(OrderRideStatus rideStatus) {
        String rideStatusStr;
        switch (rideStatus) {
            case UN_SEND://未派车
                rideStatusStr = getString(R.string.route_detail_no_charter);
                break;
            case UN_TAKEN://未上车
                rideStatusStr = getString(R.string.route_detail_wait_charter);
                break;
            case TAKEN://已上车
                rideStatusStr = getString(R.string.route_detail_take_charter);
                break;
            case ARRIVED://已到站
                rideStatusStr = getString(R.string.route_detail_finish_charter);
                break;
            case DROP://未乘坐
                rideStatusStr = getString(R.string.route_detail_cancel_charter);
                break;
            default:
                rideStatusStr = "";
        }
        return rideStatusStr;
    }

    /**
     * 设置订单价格和乘客人数
     *
     * @param bizOrder
     */
    private void setCurrentTripPrice(BizOrder bizOrder) {
        OrderBizType bizType = bizOrder.getBizType();
        switch (bizType) {
            case ORDER_BIZ_SHARE:
            case ORDER_BIZ_CHARTER:
                feeTv.setText(bizOrder.getAmount() + "人");
                passengerAmountTv.setText("");
                break;
            default:
                feeTv.setText("¥" + bizOrder.getTotalFee());
                passengerAmountTv.setText(bizOrder.getAmount() + "人");
        }
    }

    /**
     * 设置订单状态
     *
     * @param bizOrder
     */
    private void setCurrentTripOrderStatus(final BizOrder bizOrder) {
        if (bizOrder != null) {
            OrderBizType bizType = bizOrder.getBizType();
            OrderPayStatus payStatus = bizOrder.getPayStatus();
            //已下单,未支付
            if (payStatus == OrderPayStatus.CREATED) {
                switch (bizType) {
                    case ORDER_BIZ_SHARE:
                    case ORDER_BIZ_CHARTER:
                        orderStatusRl.setVisibility(View.GONE);

                        break;
                    case TICKET:
                        orderStatusRl.setVisibility(View.VISIBLE);
                        orderStatusRl.setBackgroundColor(this.getResources().getColor(R.color.font_color_blue_explanation));
                        orderStatusIv.setVisibility(View.GONE);

                        orderStatusTv.setTextColor(this.getResources().getColor(R.color.font_color_white));
                        orderStatusTv.setText(this.getString(R.string.wait_to_pay));

                        tripStatusTv.setText(this.getString(R.string.trip_management_ride_status_wait_pay));

                        orderStatusRl.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                //去支付点击事件
                                LOG.e(TAG, "去支付 onClick");
                                getAppComponent().navigator().navigateToPayment(getActivity(), mBizOrder);
                            }
                        });
                        break;
                }
            }
            //已下单,已支付
            else {
                switch (bizType) {
                    case ORDER_BIZ_SHARE:
                    case ORDER_BIZ_CHARTER:
                        orderStatusRl.setVisibility(View.GONE);
                        break;
//                    case CUSTOM_BUS:
//                        orderStatusRl.setVisibility(View.VISIBLE);
//                        orderStatusRl.setBackgroundColor(this.getResources().getColor(R.color.bg_current_trips_ticket));
//                        orderStatusIv.setVisibility(View.VISIBLE);
//
//                        orderStatusTv.setVisibility(View.VISIBLE);
//                        orderStatusTv.setTextColor(this.getResources().getColor(R.color.font_color_blue_explanation));
//                        orderStatusTv.setText(this.getString(R.string.guide_route_wdcp_title));
//
//                        orderStatusRl.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                LOG.e(TAG, "我的车票 onClick");
//                                if (getActivity() instanceof TripDetailContainerActivity) {
//                                    TripDetailContainerActivity containerActivity = (TripDetailContainerActivity) getActivity();
//                                    containerActivity.navigator.navigateToTicketCodeActivity(
//                                            mActivity,bizOrder.getOrderSerial());
//                                }
//
//                            }
//                        });
//                        break;
                    case TICKET:
                        orderStatusRl.setVisibility(View.VISIBLE);
                        orderStatusRl.setBackgroundColor(this.getResources().getColor(R.color.font_color_blue_explanation));
                        orderStatusIv.setVisibility(View.GONE);

                        orderStatusTv.setTextColor(this.getResources().getColor(R.color.font_color_white));
                        orderStatusTv.setText(this.getString(R.string.trip_detail_ticket_code));

                        orderStatusRl.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                //取票码点击事件
                                LOG.e(TAG, "乘车码 onClick");
                                String verifyCode = bizOrder.getVerifyCode();
                                GetTicketCodeDialogFragment.newInstance(verifyCode)
                                        .show(getActivity().getSupportFragmentManager(), "GetTicketCode");
                            }
                        });
                        break;

                }
            }
        }
    }

    //--------------------

    /**
     * 显示乘车人信息列表
     *
     * @param bizOrder
     */
    private void setPassengerList(BizOrder bizOrder) {
        if (bizOrder != null) {
            mPassengerList = bizOrder.getPassengerList();
            if (mPassengerList != null && mPassengerList.size() > 0) {
                mPassengerDetailAdapter = new PassengerDetailAdapter(
                        mActivity,
                        mPassengerList,
                        getChildFragmentManager(),
                        bizOrder.getOrderSerial()
                );
                innerListView.setAdapter(mPassengerDetailAdapter);
            }
        }
    }

    /**
     * 显示乘客人数
     *
     * @param amount
     */
    private void setPassengerAmount(int amount) {
        tvAmount.setText(getString(R.string.passenger_num) + "   " + amount + "人");
    }

    private void setBusVehicleLayout(String vehicleNo) {
        if (TextUtils.isEmpty(vehicleNo)) {
            busContentLl.setVisibility(View.GONE);
        }
        busVehicleNoTv.setText(vehicleNo);
    }

    /**
     * 显示订单编号
     *
     * @param orderId
     */
    private void setOrderId(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            tvOrderId.setText(getString(R.string.order_id) + " " + orderId);
        }
    }

    /**
     * 显示下单时间
     *
     * @param time
     */
    private void setGmtCreate(String time) {
        if (!TextUtils.isEmpty(time)) {
            tvGmtCreate.setText(getString(R.string.order_time) + " " + time);
        }
    }

    /**
     * 显示总费用
     *
     * @param fee
     */
    private void setTotalFee(double fee) {
        if (fee >= 0) {
            tvTotalFee.setText(getString(R.string.pay_money) + " " + fee + "元");
        } else {
            tvTotalFee.setText("");
        }
    }

    /**
     * 显示订单图标
     *
     * @param bizType
     */
    private void setBizTypeIcon(OrderBizType bizType) {
        switch (bizType) {
            case ORDER_BIZ_SHARE:
            case ORDER_BIZ_CHARTER:
                bizTypeIcon.setImageResource(R.drawable.ic_kuaiche);
                break;
            case TICKET:
                bizTypeIcon.setImageResource(R.drawable.ic_bashi_002);
                break;
            case OBT_DIY_BUS:
                bizTypeIcon.setImageResource(R.drawable.ic_dingzhibashibiaoqian);
                break;
            case OBT_FT_BUS:
                bizTypeIcon.setImageResource(R.drawable.ic_bashibiaoqian);
                break;
        }
    }

    /**
     * 显示出发地
     *
     * @param station
     */
    private void setStartStation(String station) {
        if (!TextUtils.isEmpty(station)) {
            startStation.setText(station);
        } else {
            startStation.setText("");
        }
    }

    /**
     * 显示目的地
     *
     * @param station
     */
    private void setDestination(String station) {
        if (!TextUtils.isEmpty(station)) {
            destination.setText(station);
        } else {
            destination.setText("");
        }
    }

    /**
     * 显示出发时刻和日期
     *
     * @param timeStamp
     */
    private void setStartTimeAndData(String timeStamp) {
        if (!TextUtils.isEmpty(timeStamp)) {
            String[] strings = timeStamp.split(" ");
            startData.setText(strings[0]);
            startTime.setText(strings[1]);
        }
    }

    /**
     * 显示订单价格,乘客人数,
     *
     * @param bizOrder
     */
    private void setBottomView(BizOrder bizOrder) {
        OrderBizType bizType = bizOrder.getBizType();
        switch (bizType) {
            case ORDER_BIZ_SHARE:
            case ORDER_BIZ_CHARTER:
                amount.setText(bizOrder.getAmount() + "人");
                price.setText("");
                break;
            default:
                price.setText("¥" + bizOrder.getTotalFee());
                amount.setText(bizOrder.getAmount() + "人");
        }
        setOrderStatus(bizOrder);
    }
    /*
    CREATED(1, "已下单"),PAID(2, "已支付"),INVALID(3, "已失效"),REFUNDING(4,"退款中"),
    REFUND(5,"已退款"), FINISH(6, "已完成"),CANCEL(7, "已取消");
     */

    /**
     * 显示支付状态 及相关的业务逻辑
     *
     * @param bizOrder
     */
    private void setOrderStatus(BizOrder bizOrder) {
        if (bizOrder != null) {
            final String orderId = bizOrder.getOrderSerial();
            OrderBizType bizType = bizOrder.getBizType();
            OrderPayStatus payStatus = bizOrder.getPayStatus();
            String payStatusStr;
            switch (payStatus) {
                case CREATED:
                    payStatusStr = PayStatus.CREATED.getContent();
                    break;
                case PAID:
                    payStatusStr = PayStatus.PAID.getContent();
                    break;
                case PAY_INVALID:
                    payStatusStr = PayStatus.INVALID.getContent();
                    break;
                case OPS_REFUNDING:
                    payStatusStr = PayStatus.REFUNDING.getContent();
                    break;
                case OPS_REFUND:
                    payStatusStr = PayStatus.REFUND.getContent();
                    break;
                case ORDER_FINISH:
                    JudgeEntry judgeEntry = bizOrder.getJudge();
                    if (judgeEntry == null) {
                        orderStatus.setClickable(true);
                        payStatusStr = PayStatus.FINISH.getContent();
                        orderStatus.setTextColor(getResources().getColor(R.color.font_color_blue_explanation));
                        orderStatus.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
//                                CommentDriverPopupWindowHelper.getInstance(mDetailTripPresenter, getActivity())
//                                        .showPopupWindow(mLinearLayout, orderId);
                                AppraisalDriverInfo driverInfo = getAppraisalDriverInfo();
                                getAppComponent().navigator().navigateToAppraisal(mActivity, driverInfo);
                            }
                        });
                    } else {
                        orderStatus.setClickable(false);
                        payStatusStr = String.format(getString(R.string.comment_content_ratingbar), judgeEntry.getJudgePoint());
                        orderStatus.setTextColor(getResources().getColor(R.color.font_light_black));
                    }
                    break;
                case PAY_CANCEL:
                    payStatusStr = PayStatus.CANCEL.getContent();
                    break;
                default:
                    payStatusStr = "";
            }
            orderStatus.setText(payStatusStr);
        }
    }

    private AppraisalDriverInfo getAppraisalDriverInfo() {
        AppraisalDriverInfo driverInfo = new AppraisalDriverInfo();
        driverInfo.setOrderId(mBizOrder.getOrderSerial())
                .setDriverName(mBizOrder.getDriverName())
                .setHistoryScore(Double.valueOf(mBizOrder.getAvgDriverPoint()))
                .setPlateNumber(mBizOrder.getVehicleNo());
        return driverInfo;
    }

    private void setSpecialDriverInfo(String driverName, String vehicleNo) {
        if (!TextUtils.isEmpty(driverName) && !TextUtils.isEmpty(vehicleNo)) {
            mSpecialDriverInfoTv.setText(
                    String.format(getString(R.string.route_detail_drivername), driverName.charAt(0))
                            + " " + vehicleNo);
        }
    }

    @Override
    public void renderRefundOnSuccess() {
        CancelTicketDialogFragment dialogFragment = mPassengerDetailAdapter.getCancelTicketDialogFragment();
        if (dialogFragment != null) {
            dialogFragment.dismiss();
        }

        PromptUtils.showShort(getActivity(), getString(R.string.refund_success));
    }

    @Override
    public void renderRefundOnFailure(String resultMessage) {
        CancelTicketDialogFragment dialogFragment = mPassengerDetailAdapter.getCancelTicketDialogFragment();
        if (dialogFragment != null) {
            dialogFragment.changeContent(resultMessage);
        }
    }

    @Override
    public void closeCommentOnCompleted() {
        //CommentDriverPopupWindowHelper.getInstance(mDetailTripPresenter, getActivity()).closePopupWindow();
    }

    @Override
    public void renderCommentOnError(String msg) {
        //  CommentDriverPopupWindowHelper.getInstance(mDetailTripPresenter, getActivity()).onError();
    }

    @Override
    public void renderCommentOnSuccess() {
        //CommentDriverPopupWindowHelper.getInstance(mDetailTripPresenter, getActivity()).onCommentSuccess();
    }


    @Override
    public void renderCancelOrderResult(boolean isCanceled) {
        if (isCanceled) {
            PromptUtils.showShort(mActivity, getString(R.string.cancel_order_success));
            RxBus.getInstance().send(new CancelTripOrderEvent(mBizOrder.getOrderSerial()));
            mActivity.finish();
        } else {
            PromptUtils.showLong(getActivity(), getString(R.string.trip_cancel_order_failure));
        }
    }

    @Override
    public void renderCancelError() {
        PromptUtils.showShort(mActivity, getString(R.string.trip_cancel_order_error));
    }

    @Override
    public void waitingForOrderCancel(boolean isWaiting) {
        if (isWaiting) {
            mDialogForWaitingCancel = new MaterialDialog.Builder(getActivity())
                    .content(R.string.dialog_waiting_canceling)
                    .progress(true, 0)
                    .canceledOnTouchOutside(false)
                    .show();
        } else {
            if (null != mDialogForWaitingCancel) {
                mDialogForWaitingCancel.dismiss();
            }
        }
    }

    @Override
    public void onDestroy() {
        if (mCompositeSubscription != null) {
            mCompositeSubscription.unsubscribe();
            mCompositeSubscription = null;
        }
        super.onDestroy();
    }

    @Override
    protected void initializeInjector() {
        DaggerTripComponent
                .builder()
                .appComponent(getAppComponent())
                .tripModule(new TripModule())
                .activityModule(new ActivityModule(getActivity()))
                .build()
                .inject(this);
    }

    @Override
    protected void setupToolBar() {
        ((TripDetailContainerActivity) mActivity).setToolbar(getString(R.string.trip_detail_header_title), R.drawable.icon_share);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_trips_detail;
    }

}
